<template>
	<view class="pages">
		<uni-nav-bar statusBar fixed height="60px" left-icon="left" backgroundColor="#F5F7F8" @clickLeft="back" right-icon="trash"
			@clickRight="showModel" title="我的收藏" />
		<mescroll-body height="500px" :sticky="true" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="down">
			<view class="list-type">
				<view :class="current== 1?'item-type select-type':'item-type'" @click="change(1)">
					<view>关注技师</view>
				</view>
				<view :class="current== 2?'item-type select-type':'item-type'" @click="change(2) ">
					<view>关注服务</view>
				</view>
			
			</view>
			<view class="box-content" v-if="current == 2">
				<view class="list-content-inner">
					<view class="item" @click="toDetail(0,item)" @longpress.stop="longClick(item)" v-for="(item,index) in data" :key="index">
						<image :src="item.images && item.images[0]" mode="aspectFill"></image>
						<view class="cancel-content" v-if="item.isshow">
							<view class="cancel-btn" @click.stop="cancelAttion(item)">取消关注</view>
						</view>
						<view style="padding: 0 20rpx;">
							<view>{{item.title}}</view>
							<view class="slod-num">
								已售{{item.buy_num}}
								<view class="lines"></view>
								好评{{((item.high_opinion/item.opinion || 0)*100).toFixed(0)}}%
							</view>
							<view class="price">{{item.price}}
								<view>元/次</view>
							</view>
						</view>

					</view>
				</view>
			</view>
			<view class="box-content" v-else>
				<view class="technician-list">
					<view v-for="(item,index) in data" :key="item.id" style="margin-bottom: 34rpx;">
						<uni-swipe-action>
							<uni-swipe-action-item :right-options="options" @click="cancelAttion(item)">
								<view class="every-technician-info" @click.stop="toDetail(1,item)">
									<view class="left-show">
										<view class="technician-img">
											<image class="header-img" :src="item.work_clothes_image" mode="aspectFill">
											</image>
											<image class="fangda-icon" src="../../static/jishi/big.png" mode="">
											</image>
										</view>
									</view>
									<view class="right-show">
										<view style="display: flex;align-items: center;">
											<view class="username">{{item.technician_nickname || item.real_name}}</view>
											<view class="fixed-loc">
												<image src="../../static/jishi/loc.png" mode=""></image>
												<view>{{item.juli/1000}}km</view>
											</view>
											<view class="today-time">
												<view class="titles">最快上门</view>
												<view class="time">30分钟</view>
											</view>
										</view>
										<view class="tit">
											<view>{{item.age}}</view>
											<view>{{item.nation}}</view>
										</view>
										<view class="start-nums">
											<view class="start-show">
												<uni-rate :readonly="true" activeColor="#EF5233" :size="14" :max="5" :value="item.star" />
											</view>
											<view class="pingjia-nums">
												<text>评论{{item.opinion}}</text>
												<text>好评{{((item.high_opinion/item.opinion || 0)*100).toFixed(0)}}%</text>
											</view>
										</view>
										
										<view class="brief-introduction">
											正规绿色服务!擅长中式推拿、精油SPA、美容理疗，有
											按摩师证，手法专业，期待您的关注和预约~
										</view>
									</view>
								</view>
							</uni-swipe-action-item>
						</uni-swipe-action>
					</view>
				</view>
			</view>
		</mescroll-body>
	<uni-popup ref="alertDialog" type="dialog">
		<uni-popup-dialog type="warn" cancelText="关闭" confirmText="同意" title="提示" content="是否全部取消关注？"
			@confirm="cancelAttionAll"></uni-popup-dialog>
	</uni-popup>
	</view>
</template>

<script>
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	export default {
		mixins: [MescrollMixin],
		data() {
			return {
				options: [{
					text: '取消关注',
					style: {
						backgroundColor: '#EF5233'
					}
				}],
				current: 1,
				data: [],
				attentionList: [{
						'id': 0,
						'title': '关注技师'
					},
					{
						'id': 1,
						'title': '关注服务'
					}
				],
				down: {
					auto: false
				}
			}

		},
		onLoad() {},
		onShow() {
			this.downCallback()
		},
		methods: {
			toDetail(type,item){
				if(type == 0){
					uni.navigateTo({
						url: "/otherpages/massage/massageDetail?id=" + item.id
					})
				}else{
					uni.navigateTo({
						url:"/otherpages/technician/technician?id="+item.id
					})
				}
			},
			change(index) {
				this.current = index
				this.downCallback()
			},
			back() {
				uni.navigateBack()
			},
			longClick(item) {
				item.isshow = true
			},
			showModel() {
				this.$refs.alertDialog.open()
			},
			cancelAttionAll() {
				let that = this
				this.request.httpTokenRequest({
					url: "service/closeCollect",
					method: "get"
				}, {
					type: this.current == 2 ? 2 : 1
				}).then(res => {
					if (res.code == 0) {
						this.downCallback()
						this.$util.msg(res.msg)
					} else {
						this.$util.msg(res.msg)
						return
					}
				}, error => {})
			},
			cancelAttion(item) {
				let that = this
				this.request.httpTokenRequest({
					url: "service/collect",
					method: "POST"
				}, {
					id: item.id,
					type: this.current == 2 ? 2 : 1
				}).then(res => {
					if (res.code == 0) {
						this.downCallback()
						this.$util.msg(res.msg)
					} else {
						this.$util.msg(res.msg)
						return
					}
				}, error => {})
			},
			downCallback() {
				this.data = []
				this.mescroll&&this.mescroll.resetUpScroll()
			},
			upCallback(page) {
				let opts = {
					url: "user/collectService",
					method: 'get'
				}
				let param = {
					page: page.num,
					type: this.current == 2 ? 2 : 1
				};
				this.request.httpTokenRequest(opts, param).then(res => {
					res.data.data.map(item => {
						item.isshow = false
						this.data.push(item)
					})
					this.mescroll.endSuccess(this.data.length,this.data.length == res.data.total?false:true);
				}, error => {

				})
			},
		}
	}
</script>

<style lang="scss">
	.list-type {
		position: sticky;
		top: calc(var(--status-bar-height) + 60px);;
		display: flex;
		align-items: flex-end;
		justify-content: space-around;
		// margin-top: 20rpx;
		z-index: 100;
		background-color: #F5F7F8;
		.item-type {
			width: 40%;
			text-align: center;
			padding: 10rpx 0;
			font-size: 30rpx;
			font-family: PingFangSC, PingFang SC;
			font-weight: 400;
			color: #1E1E1E;
			border-bottom: 4rpx solid #F5F7F8;
		}

		.select-type {
			font-weight: bold;
			border-bottom: 4rpx solid #C6C7C8;
		}
	}

	.list-content {
		margin-top: 30rpx;
		background: #fff;
		border-radius: 20rpx;
		padding: 29rpx 24rpx;
	}

	//
	.list-content-inner {
		display: flex;
		align-items: center;
		justify-content: space-between;
		flex-wrap: wrap;
		border-radius: 20rpx;
		padding: 30rpx 0;
	}

	.item {
		width: 48%;
		flex: 0 0 auto;
		border-radius: 10rpx;
		position: relative;
		overflow: hidden;
		border: 1rpx solid #F0F0F0;
		padding-bottom: 20rpx;
		background-color: #fff;
		image {
			width: 100%;
			height: 409rpx;
		}

		.cancel-content {
			background-color: rgba(0, 0, 0, .6);
			text-align: center;
			position: absolute;
			top: 0;
			right: 0;
			left: 0;
			height: 409rpx;

			.cancel-btn {
				width: 240rpx;
				height: 80rpx;
				background: rgba(216, 216, 216, 0.3);
				border-radius: 45rpx;
				border: 1rpx solid #FFFFFF;
				text-align: center;
				line-height: 80rpx;
				font-size: 34rpx;
				font-family: PingFangSC, PingFang SC;
				font-weight: 400;
				color: #FFFFFF;
				margin: 165rpx auto;
			}
		}

		.slod-num {
			font-size: 20rpx;
			font-family: PingFangSC, PingFang SC;
			font-weight: 400;
			color: #DE8C3E;
			line-height: 28rpx;
			margin-bottom: 10rpx;
			display: flex;
			align-items: center;
			margin-top: 10rpx;

			.lines {
				width: 1rpx;
				height: 20rpx;
				border: 1rpx solid #DBDBDB;
				margin: 0 10rpx;
			}
		}

		.price {
			display: flex;
			align-items: center;
			line-height: 40rpx;
			font-weight: bold;
			color: #d4282d;
			font-size: 28rpx;
			line-height: 42rpx;

			view {
				font-size: 18rpx;
				font-family: PingFangSC, PingFang SC;
				font-weight: 400;
				color: #EC2700;
				line-height: 25rpx
			}
		}

	}

	.nums {
		display: flex;
		align-items: center;
		font-size: 28rpx;
		font-family: PingFangSC, PingFang SC;
		font-weight: 400;
		color: #FFFFFF;
		position: absolute;
		bottom: 23rpx;
		left: 21rpx;

		image {
			width: 49rpx;
			height: 42rpx;
			margin-right: 11rpx;
		}
	}

	//
	//
	//
	.selectstyle {
		border: 2rpx solid #EF5233;
	}
	.technician-list{
		padding: 30rpx 0;
	}
	.every-technician-info {
		// height: 261rpx;
		background-color: #fff;
		border-radius: 10rpx;
		padding: 20rpx 31rpx;
		// position: relative;
		display: flex;
		align-items: center;
		// margin-top: 30rpx;

		.left-show {
			// position: absolute;
			// left: 24rpx;
			// top: 30rpx;
			margin-right: 20rpx;

			.technician-img {
				width: 160rpx;
				height: 200rpx;
				position: relative;

				.header-img {
					width: 160rpx;
					height: 200rpx;
				}

				.fangda-icon {
					width: 30rpx;
					height: 30rpx;
					position: absolute;
					top: 10rpx;
					right: 10rpx;
				}

			}

			.choose-style {
				width: 118rpx;
				height: 30rpx;
				margin: 0 auto;
				margin-top: 30rpx;

				.no-choose {
					width: 115rpx;
					height: 30rpx;
					background: url('../../static/jishi/nochoose.png')no-repeat;
					background-size: 100% 100%;
					font-size: 20rpx;
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					color: #FFFFFF;
					padding-left: 17rpx;
					line-height: 30rpx;
				}

				.choose {
					width: 115rpx;
					height: 30rpx;
					background: url('../../static/jishi/choose.png')no-repeat;
					background-size: 100% 100%;
					font-size: 20rpx;
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					color: #FFFFFF;
					padding-left: 17rpx;
					line-height: 30rpx;
				}
			}
		}

		.right-show {
			flex-grow: 1;
			.today-time {
				width: 186rpx;
				height: 32rpx;
				margin-left: auto;
				background: url('https://qiniu-cdn.maeiyun.com/imgs/massage/bg.png')no-repeat;
				background-size: 100% 100%;
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding: 0 12rpx;

				.titles {
					font-size: 20rpx;
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					color: #FFFFFF;
				}

				.time {
					font-size: 20rpx;
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					color: #EF5233;
				}
			}

			.fixed-loc {
				margin-left: 30rpx;
				display: flex;
				align-items: baseline;
				height: 30rpx;
				background: #F3F3F3;
				border-radius: 150rpx;
				padding: 0 14rpx;
				justify-content: center;
				align-items: center;
				line-height: 30rpx;

				view {
					font-size: 18rpx;
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					color: #0F0807;
				}

				image {
					width: 14rpx;
					height: 18rpx;
					margin-right: 6rpx;
				}
			}

			.username {
				font-size: 28rpx;
				font-family: PingFangSC, PingFang SC;
				font-weight: 400;
				color: #0F0807;

				text {
					font-size: 20rpx;
				}
			}

			.tit {
				display: flex;
				align-items: center;
				margin-top: 15rpx;

				view {
					height: 30rpx;
					background: rgba(216, 216, 216, 0.46);
					border-radius: 8rpx;
					font-size: 20rpx;
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					color: #0F0807;
					padding: 0 12rpx;
					margin-right: 10rpx;
					line-height: 30rpx;

				}
			}

			.start-nums {
				display: flex;
				align-items: center;
				margin-top: 15rpx;

				.start-show {
					margin-right: 42rpx;

					image {
						width: 19rpx;
						height: 18rpx;
					}
				}

				.pingjia-nums {
					display: flex;
					align-items: center;

					text {
						font-size: 20rpx;
						font-family: PingFangSC, PingFang SC;
						font-weight: 400;
						color: #888889;
						margin-right: 10rpx;
					}
				}
			}

			.brief-introduction {
				font-size: 22rpx;
				font-family: PingFangSC, PingFang SC;
				font-weight: 400;
				color: #0F0807;
				margin-top: 14rpx;
				display: -webkit-box;
				overflow: hidden;
				white-space: normal!important;
				text-overflow: ellipsis;
				word-wrap: break-word;
				-webkit-line-clamp: 3;
				-webkit-box-orient: vertical
			}
		}
	}

	//筛选弹窗
	.popup-content {
		width: 511rpx;

		.screening-condition {
			padding: 33rpx;
			border-bottom: 30rpx solid #D8D8D8;

			.screening-title {
				font-size: 28rpx;
				font-family: PingFangSC, PingFang SC;
				font-weight: 400;
				color: #000000;
				line-height: 40rpx;
			}

			.slider-content {
				margin-top: 55rpx;
				padding-bottom: 30rpx;
			}

			.sex-content {
				margin-top: 30rpx;

				.all-ok {
					width: 138rpx;
					height: 60rpx;
					border-radius: 30rpx;
					border: 1rpx solid #D7D7D7;
					font-size: 24rpx;
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					color: #000000;
					text-align: center;
					line-height: 60rpx;
				}

				.all-ok-select {
					background: rgba(239, 82, 51, 0.1);
					border-radius: 30rpx;
					border: 1rpx solid #EF5233;
					color: #EF5233;
				}

				.else-sex {
					display: flex;
					align-items: center;
					justify-content: space-between;
					margin-top: 50rpx;

					.sex-box {
						width: 210rpx;
						height: 60rpx;
						border-radius: 30rpx;
						border: 1rpx solid #D7D7D7;
						display: flex;
						align-items: center;
						text-align: right;
						position: relative;

						view {
							width: 100%;
							font-size: 24rpx;
							font-family: PingFangSC, PingFang SC;
							font-weight: 400;
							color: #000000;
							text-align: right;
							padding-right: 30rpx;
						}

						image {
							width: 89rpx;
							height: 89rpx;
							position: absolute;
							bottom: 0;
							left: 16rpx;
						}
					}

					.sex-box-select {
						background: rgba(239, 82, 51, 0.1);
						border-radius: 30rpx;
						border: 1rpx solid #EF5233;

						view {
							color: #EF5233;
						}
					}
				}
			}

			//
			.age-fillin {
				display: flex;
				align-items: center;
				margin-top: 30rpx;

				.lines {
					width: 18rpx;
					height: 1rpx;
					background-color: #979797;
					margin: 0 8rpx;
				}

				input {
					width: 210rpx;
					height: 60rpx;
					background: #F3F3F3;
					border-radius: 30rpx;
					font-size: 24rpx;
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					color: #000000;
					text-align: center;
				}
			}

			.age-list {
				display: flex;
				align-items: center;
				justify-content: space-around;
				margin-top: 30rpx;

				view {
					width: 138rpx;
					height: 60rpx;
					border-radius: 30rpx;
					border: 1rpx solid #D7D7D7;
					font-size: 24rpx;
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					color: #000000;
					line-height: 60rpx;
					text-align: center;
				}
			}

			.technician-name {
				width: 452rpx;
				height: 60rpx;
				background: #F3F3F3;
				border-radius: 30rpx;
				font-size: 24rpx;
				font-family: PingFangSC, PingFang SC;
				font-weight: 400;
				color: #000000;
				text-align: center;
				margin-top: 30rpx;
			}
		}
	}
</style>